package com.zjcode.cdcer.controller;

import com.chinatechstar.component.commons.result.ListResult;
import com.chinatechstar.component.commons.result.ResultBuilder;
import com.chinatechstar.component.commons.supports.PageData;
import com.zjcode.cdcer.model.basic.JsonObj;
import com.zjcode.cdcer.service.CerReportProgressService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * @ClassName:CerReportProgressController
 * @功能：上报进度信息
 **/
@RestController
@Slf4j
@RequestMapping("/v1/reportProgress/")
public class CerReportProgressController {

    @Autowired
    private CerReportProgressService cerReportProgressService;

    @PostMapping("listPageData")
    @ApiOperation("获取所有的上报进度信息列表")
    public ListResult<Object> listPageData(@RequestBody PageData pageData) {
        Object type = pageData.get("type");
        if (Objects.isNull(type)) {
            pageData.put("type", 1);
        }
        return ResultBuilder.buildListSuccess(cerReportProgressService.listPageData(
                pageData));
    }

    @PostMapping("exportData")
    @ApiOperation("点击导出按钮，获取所有的上报进度信息列表")
    public JsonObj exportData(@RequestBody PageData pageData) {
        Object type = pageData.get("type");
        if (Objects.isNull(type)) {
            pageData.put("type", 1);
        }
        List<LinkedHashMap<String,Object>> list  = cerReportProgressService.queryAll(
                pageData);
        Map<String,Object> map = new HashMap<>();
        map.put("data",list);
        map.put("type",pageData.get("type"));
        return JsonObj.success(map);
    }
}
